from django.http import HttpResponseForbidden

from contents.models import GoodsCategory, GoodsChannel


def bread_crumb(id):
    try:
        cat3 = GoodsCategory.objects.get(id=id)
    except GoodsCategory.DoesNotExist:
        return HttpResponseForbidden('非法id')
    cat2 = cat3.parent
    cat1 = cat3.parent.parent
    cat1.url = GoodsChannel.objects.filter(category=cat1)[0].url
    # 面包屑导航
    breadcrumb = {'cat1': cat1, 'cat2': cat2, 'cat3': cat3}
    return breadcrumb,cat3
